package com;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/**
 * DriverManager作用  1注册驱动    DriverManager.registerDriver(new Driver());
 *                   2获取数据库连接   DriverManager.getConnection(url,user,password);
 *
 */

public class JDBCDemo02_DriverManager {
   public static void main(String[] args) throws Exception {
        //1.注册驱动
       //可省略 lib\mysql-connector-java-5.1.48.jar!\META-INF\services\java.sql.Driver 下有响应的驱动
      //Class.forName("com.mysql.jdbc.Driver");
       //2.获取连接  
       //String url="jdbc:mysql://127.0.0.1:3306/db01";
       //如果连接的是本机mysql服务器，并且mysql服务默认端口是3306，则url可以简写为：jdbc:mysql:///数据库名称?参数键值对&
       //配置 useSSL=false 参数，禁用安全连接方式，解决
       //警告提示
       String url="jdbc:mysql:///db01?useSSL=false";
       String user="root";
       String password="137867";
       Connection connection = DriverManager.getConnection(url,user,password);
       //3编写sql
       String sql="update tb01 set number=2000 where id=1";
       //4.执行sql对象
       Statement statement = connection.createStatement();
       //5.执行sql
       int i = statement.executeUpdate(sql);
       //6处理结果
       System.out.println(i);
       //7关闭资源
       statement.close();
       connection.close();
    }
}
